



//
//  WZWelcomController.swift
//  weibo
//
//  Created by mac on 16/2/29.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SDWebImage
import SnapKit
class WZWelcomController: UIViewController {

    
    
    override func loadView() {
        view = bgImageView
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        setUI()
        setWelcomVCAnimation()
    }
    
    func setWelcomVCAnimation(){
        
        iconImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view.snp_bottom).offset(-UIScreen.mainScreen().bounds.height+100)
            make.centerX.equalTo(self.view.snp_centerX)
            make.size.equalTo(CGSizeMake(170/2, 170/2))
            
            
            UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity:4, options: [], animations: { () -> Void in
                self.view.layoutIfNeeded()
                }, completion: { (_) -> Void in
                    NSNotificationCenter.defaultCenter().postNotificationName(KchangeRootVC, object: nil)
            })
            
            
        }
        
        
    
        
    }
    
    
    
    
    
    
    
    
    
    
    
    //    MARK:设置方法更新UI并设置约束
    func setUI(){
        
        
        view.addSubview(iconImageView)
        view.addSubview(nameLabel)
        
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(view.snp_bottom).offset(-300)
            make.centerX.equalTo(view.snp_centerX)
            make.size.equalTo(CGSizeMake(170/2, 170/2))
        }
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImageView.snp_bottom).offset(10)
            make.centerX.equalTo(view.snp_centerX)
            
            
        }
        
        
    }
    
//    MARK:对空间进行懒加载
    lazy var bgImageView: UIImageView = {
    
        let imageView = UIImageView()
        
        imageView.image = UIImage(named: "ad_background")
        
        return imageView
    }()
    lazy var iconImageView: UIImageView = {
        
        let imageview = UIImageView()
        
        if  let url = NSURL(string: (WZUserViewModel.shareInstance.userModel?.profile_image_url)!){
            
            imageview.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar_default_big"))
            
        }
//imageview.image = UIImage(named: "avatar_default_big")
       
        imageview.layer.cornerRadius = 170/4
        imageview.layer.masksToBounds = true
        imageview.layer.borderWidth = 2
        imageview.layer.borderColor = UIColor.grayColor().CGColor
        return imageview
    }()
    
    
    lazy var nameLabel: UILabel = {
        
        let lable = UILabel()
        
        if let lableText = WZUserViewModel.shareInstance.userModel?.screen_name{
            lable.text = "\(lableText)欢迎回来"
            
        }

        lable.font = UIFont.systemFontOfSize(15)
        lable.textColor = UIColor.darkGrayColor()
       
        lable.textAlignment = .Center
        return lable
        
    }()
    deinit{
        NSNotificationCenter.defaultCenter().removeObserver(self, name: KchangeRootVC, object: nil)

    }
}
